/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2012 Steffen Nissen (sn@leenissen.dk)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>

#include "fann.h"

int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
	unsigned int max_epochs, unsigned int epochs_between_reports, 
	float desired_error, unsigned int epochs)
{
	printf("Epochs     %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
	return 0;
}

int getActivationFunction(int param){
	switch (param)
	{
	case 0:
		return FANN_SIGMOID;
		break;
	case 1:
		return FANN_SIGMOID_STEPWISE;
		break;
	case 2:
		return FANN_SIGMOID_SYMMETRIC;
		break;
	case 3:
		return FANN_LINEAR;
		break;
	case 4:
		return FANN_THRESHOLD;
		break;
	default:
		return -1;
		break;
	}
}

int main(int argc, char *argv[])
{
	const char* ext = ".net";

	if (argc < 6 )
	{
		printf("0\nBadNumberOfParams");
		return 0;
	}

	int i;
	int numberLayer = atoi(argv[1]);
	int *layers = (int *)malloc(sizeof(int)* numberLayer);
	for (i = 0; i < numberLayer; i++)
	{
		layers[i] = atoi(argv[2+i]);
 	}

	i += 2;
	float activationSteepnessHidden = atof(argv[i]);
	float activationSteepnessOutput = atof(argv[i+1]);
	int activationFunctionHidden = atoi(argv[i+2]);
	int activationFunctionOutput = atoi(argv[i+3]);
	char* name = argv[i + 4];
	char* source = (char *)malloc(1 + strlen(name) + strlen(ext));
	strcpy(source, name);
	strcat(source, ext);

	struct fann *ann;

	unsigned int decimal_point;

	
	ann = fann_create_standard_array(numberLayer, layers);
	fann_set_activation_steepness_hidden(ann, activationSteepnessHidden);
	fann_set_activation_steepness_output(ann, activationSteepnessOutput);

	fann_set_activation_function_hidden(ann, getActivationFunction(activationFunctionHidden));
	fann_set_activation_function_output(ann, getActivationFunction(activationFunctionOutput));
	
	fann_save(ann, source);
	printf("1\n%s", source);
	fann_destroy(ann);
	return 0;
}


